﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Conventions;

namespace Landscape.Business.FNH
{
    public class ManyToManyConvention //: IHasManyToManyConvention
    {

        public void Apply(FluentNHibernate.Conventions.Instances.IManyToManyCollectionInstance instance)
        {
            if (instance.OtherSide == null)
            {
                instance.Table(
                   string.Format(
                       "{0}_TO_{1}",
                       instance.EntityType.Name.ToUpper(),
                       instance.ChildType.Name.ToUpper()));
            }
            else
            {
                instance.Inverse();
            }
            instance.Cascade.All();

        }
    }
}
